package ru.spb.osll.myfit.common.chart;

import java.io.Serializable;
import java.util.*;

public class ChartTreeNode implements Comparable<ChartTreeNode>, Serializable {
  private static final long serialVersionUID = -86716584411086845L;

  private String m_name;
  private ChartTreeNode m_parent = null;
  private Map<String, ChartTreeNode> m_children = new TreeMap<String, ChartTreeNode>();
  private Set<Launch> m_launchList = new TreeSet<Launch>();

  public ChartTreeNode() {}

  public ChartTreeNode(String name, ChartTreeNode parent) {
    m_name = name;
    if (parent != null) {
      m_parent = parent;
      m_parent.addChild(m_name, this);
    }
  }

  private void addChild(String name, ChartTreeNode node) {
    m_children.put(name, node);
  }

  @Override
  public int compareTo(ChartTreeNode chartTreeNode) {
    return m_name.compareTo(chartTreeNode.m_name);
  }

  public void addLaunch(Launch launch) {
    m_launchList.add(launch);
  }

  public boolean hasNode(String name) {
    return m_children.containsKey(name);
  }

  public ChartTreeNode getNode(String name) {
    return m_children.get(name);
  }

  public Collection<ChartTreeNode> getChildren() {
    return m_children.values();
  }

  public String getName() {
    return m_name;
  }

  public Set<Launch> getLaunches() {
    return m_launchList;
  }
}
